/*
 * @Description: 抽取单表增查删改
 * @Date: 2019-10-14 11:08:46
 * @LastEditTime: 2020-03-19 12:26:38
 * @LastEditors: 魏勇
 */

import { Loading } from 'element-ui';
export default {
    components: {},
    data() {
        return {
            winTitle:"新增",
            isShowAddDialog:false,
            curRecordId:null,
            winWidth:500,
            btns:[
                {id:'flush',label:'刷新',icon:'el-icon-refresh',type:'iconBtn'},
                {id:'add',label:'新增',icon:'el-icon-plus'},
                {id:'mod',label:'修改',icon:'el-icon-edit'},
                {id:'del',label:'删除',icon:'el-icon-delete'}
            ]
        }
    },
    computed: {

    },
    methods: {
        //刷新数据
        flush(){
            let LoadingIn=Loading.service({text:"加载中"});
            let backFun=()=>{
                LoadingIn.close();
            }
            this.searchGridByCondition&&this.searchGridByCondition("",backFun);
            this.$emit("flush","")
        },
        //按钮点击事件
        btnClick({id}){
            this[id]&&this[id]();
        },
        //删除操作
        del(){
            let rowId=this.$refs.tableObj.getRowIds();
            if(rowId!=null&&rowId!==""){
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.delOk&&this.delOk(rowId);
                }).catch(() => {

                });

            }else{
                this.$message.error('请选择相应的记录后再进行操作！');
            }
        },
        //购买按钮
        purchase() {
            this.winTitle="购买";
            this.isShowPurchaseWin = true;
            this.beforeAdd&&this.beforeAdd();
        },
        // 购买记录按钮
        purchaseRecords() {
            this.isShowPurchaseRecordsWin = true;
        },
        //关闭新增窗口
        closeAddWin(){
            this.isShowAddDialog=false;
            this.isShowPurchaseWin = false;
        },
        //添加按钮
        add(){
            this.winTitle="新增";
            this.beforeAdd&&this.beforeAdd();
            this.isShowAddDialog=true;
            this.winTitle="新增";
        },
        //修改操作
        mod(){
            let rowId=this.$refs.tableObj.getRowId();
            if(rowId!=null&&rowId!==""){
                this.isShowAddDialog=true;
                this.winTitle="修改";
                this.beforeMod&&this.beforeMod();
                this.loadRecord&&this.loadRecord(rowId);
            }else{
                this.$message.error('请选择相应的记录后再进行操作！');
            }
        },
        //添加确定
        addConfirm(){
            //校验数据
            if(this.$refs.dynamicForm.validate()){
                this.confirmOk&&this.confirmOk();
            }
        },
    }

}